#ifndef RTC_HEAD
#define RTC_HEAD

#include <led.h>
#include <stm32f10x.h>

//control bit in RCC_APB1ENR
#define PWREN 0x10000000	//Power interface clock enable
#define BKPEN 0x08000000	//Backup interface clock enable
//control bit in RCC_BDCR
//LSE只给RTC提供时钟，LSEON应该不会出现在其他文件中
#define BDRST 0x00010000 	//Backup domain software reset
#define RTCEN 0x00008000 	//RTC clock enable
#define LSECK 0x00000100	//LSE as RTC_CLK
#define LSICK 0x00000200	//LSI as RTC_CLK
#define HSECK 0x00000300	//HSE/128 as RTC_CLK
#define LSERDY 0x00000002	//External low-speed oscillator ready
#define LSEON 0x00000001	//External low-speed oscillator enable
//control bit in PWR_CR
#define DBP   0x00000100	//Enable writing backup domain
//RTC_CRH
#define OWIE  0x0004 		//Overflow interrupt enable
#define ALRIE 0x0002 		//Alarm interrupt enable
#define SECIE 0x0001 		//Second interrupt enable
//RTC_CRL
#define RTOFF 0x0020  		//RTC operation off
#define CNF   0x0010 		//Config flag
#define RSF   0x0008 		//Registers synchronized flag
#define OWF   0x0004 		//Overflow flag
#define ALRF  0x0002 		//Alarm flag
#define SECF  0x0001 		//Second flag

struct Time
{
	unsigned short year;
	unsigned char month, date, hour, minute, second;
};

extern const unsigned char days[24];
extern unsigned char Is_leap;

unsigned char RTC_Check(void);
void Time_Reset(struct Time *start_time);
void Get_time(struct Time *current_time);
unsigned char RTC_Init(unsigned int prl);

#endif
